package com.example.zhaoy.rebook.net;

import com.example.zhaoy.rebook.dao.Book;
import com.example.zhaoy.rebook.dao.Debit;
import com.example.zhaoy.rebook.dao.User;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

/**
 * Created by zhaoy on 2017/3/19.
 */
public class CustomServerAPI {
    private final static String HOST = "http://ip::8080/rebook/";
    private HttpURLConnection connection;

    public CustomServerAPI() {
    }

    public boolean regsiter(final User user) {
        if(getConnection("resgiter.action?username=" + user.getName())){

        }
        return true;
    }

    public boolean login(final User user) {
        if (getConnection("login.action?username=" + user.getName())) {

        }
        return true;
    }

    public User queryUser(String name) {
        return null;
    }

    public boolean modifyUserInfo() {
        return true;
    }

    public static boolean addBook() {
        return true;
    }

    public boolean deleteBook(User user) {
        return true;
    }

    public List<Book> getSearchBook() {
        return null;
    }

    //首页上的书
    public static List<Book> getReCommandBooks() {
        return null;
    }

    public static List<Book> getUserBook(final User user) {
        return null;
    }

    public boolean addDebit() {
        return true;
    }

    public List<Debit> getDebits() {
        return null;
    }

    //测试用
    private boolean getConnection(final String method){
        return true;
    }
//    private boolean getConnection(final String method) {
//        try {
//            final URL url = new URL(HOST + method);
//            connection = (HttpURLConnection) url.openConnection();
//            connection.connect();
//            if (connection.getResponseCode() == 200) {//请求成功
//                return true;
//            }
//        } catch (IOException e) {
//            e.printStackTrace();
//            return false;
//        }
//
//        return false;
//    }

    public static void main(String args[]) {

    }
}
